package com.huaxin.dss2.data.bean;

import java.util.Objects;
import lombok.Getter;
import lombok.Setter;

/**
 * Created by HX-119 on 2014/6/30.
 */
@Getter
@Setter
public class DataInfo {

    /**
     * 首创的station表中厂站编码为stationCode
     */
    private String stationCode;

    /**
     * 嘉靖的station表中厂站编码为orgCode
     */
    private String orgCode;

    private Integer dataItemId;
    private String dataCode;
    private Integer storageInterval;
    private Integer isStorage;
    private Double maxLimit=Double.MAX_VALUE;
    private Double highLimit=Double.MAX_VALUE;
    private Double lowLimit=-Double.MAX_VALUE;
    private Double minLimit=-Double.MAX_VALUE;
    private Integer ifShow;
    private String formula;
    private Integer collectTime;
    /**
     * 存储频率
     * 1: 1小时一次
     * 0: 正常存储频率
     */
    private String saverate;
    private Long lastTime = 0L;

    /**
     * 获取三段编码 stationCode_dataItemId_dataCode
     * @return 三段编码
     */
    public String getFullDataCode(){
        this.stationCode = (stationCode == null) ? orgCode : stationCode;
        return this.stationCode+'_'+this.dataItemId+'_'+this.dataCode;
    }


    public void setMaxLimit(Double maxLimit) {
        if(null!=maxLimit) {
            this.maxLimit = maxLimit;
        }
    }

    public void setHighLimit(Double highLimit) {
        if(null!=highLimit) {
            this.highLimit = highLimit;
        }
    }

    public void setLowLimit(Double lowLimit) {
        if(null!=lowLimit) {
            this.lowLimit = lowLimit;
        }
    }

    public void setMinLimit(Double minLimit) {
        if(null!=minLimit) {
            this.minLimit = minLimit;
        }
    }

    public Long getNextTime(){
        //如果保存状态是1 这按1小时存储一次的频率
        if (saverate == null || Objects.equals("1",saverate)){
            return this.lastTime + 60*60*1000;
        }

        //否则按照正常频率
        return 0L;
    }

    public void updateLastTime(){
        this.lastTime = System.currentTimeMillis();
    }
}
